define('components/process/process.tpl',['hdbr'], function(Handlebars) {
			return Handlebars.template({"1":function(container,depth0,helpers,partials,data) {
    var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;

  return "    <li>\r\n      <div>\r\n        <div class=\""
    + alias4(((helper = (helper = helpers.className || (depth0 != null ? depth0.className : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"className","hash":{},"data":data}) : helper)))
    + " step-num\">"
    + alias4((helpers.addOne || (depth0 && depth0.addOne) || alias2).call(alias1,(data && data.index),{"name":"addOne","hash":{},"data":data}))
    + "</div>\r\n        <div class=\"step-name\">"
    + alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
    + "</div>\r\n      </div>\r\n    </li>\r\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
    var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});

  return "<div class=\"sn-step\">\r\n  <ol class=\"sn-stepbar "
    + container.escapeExpression(((helper = (helper = helpers.className || (depth0 != null ? depth0.className : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"className","hash":{},"data":data}) : helper)))
    + "\">\r\n"
    + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.items : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
    + "  </ol>\r\n  <div class=\"formContainer\"></div>\r\n</div>";
},"useData":true})
		});

define('lib/requirejs/css.min!components/process/process',[],function(){});
/**
 *Created by jingfei on 2016/10/8.
 */
define('process',[
    'jquery',
    'eventTarget',
    'hdbr',
    'components/process/process.tpl',
    'lib/requirejs/css.min!components/process/process.css'
    ],function ($, eventTarget, hdbr, template) {
    var VERSION = '1.1.1';
    var objClass = function(options){
        //判断el的异常值，el不存在、为空string、
        if(!options.el||options.el.length==0){
            this.$el = $("<div></div>")
            // return false
        }else if (typeof(options.el) == 'string'&&options.el.length>0) {
            if($(options.el).length>0){
                this.$el = $(options.el);
            }else{
                this.$el = $("<div></div>")
            }
        }else if(isDOM(options.el)){
            this.$el = $(options.el);
        }else{
            this.$el = options.el;
        }

        this.options = options; 
        eventTarget.call(this);
        render.call(this);
        eventInit.call(this);
        setTimeout($.proxy(processInit, this), 200); 
    };

    $.extend(objClass.prototype,eventTarget.prototype,{
        version:VERSION
    });

    var processInit = function () {
        var $li = this.$el.find('.sn-step>.sn-stepbar>li');
        var $liFirst = $li.first(),
            $liLast = $li.last(),
            length = $li.length,
            width = this.options.width/length||160,
            height = this.options.height||61,
            form = '';
        for(var i = 0;i<length;i++){
            form+='<div class="formContainer'+(i+1)+'"></div>';
        }
        this.$el.find('.sn-step>.formContainer').append(form);
        if ($liFirst.length) {
            $liFirst.addClass('step-first');
            $liFirst.children().children('.step-name').addClass('step-now');
            $liFirst.children().addClass('step-current').children('.step-num').trigger('click');
        }else{
            console.log('还没有配置进度条内容')
        }

        if ($liLast.length) {
            $liLast.addClass('step-last');
        }else{
            console.log('还没有配置进度条内容')
        }
        $li.css(
            {
                'width':width,
                'height':height
            }
        );     
    };

    var render = function(){
        var handleHelper = hdbr.registerHelper("addOne",function(index){
            return index+1;
        });
//      template = hdb.compile(tpl);
        this.$el.html(template(this.options));
    };

    //自定义事件
    var eventInit = function(){
        this.$el.on('click','.sn-step>.sn-stepbar>li>.step-done>.step-num',$.proxy(function(e,nextIndex,nowIndex,res){
            itemsClick.call(this,e,nextIndex,nowIndex,res);
            this.trigger('itemsClick',[e,nextIndex,nowIndex,res]);
        },this));
        this.$el.on('click','.sn-step>.sn-stepbar>li>.step-current>.step-num',$.proxy(function(e,nextIndex,nowIndex,res){
            itemsClick.call(this,e,nextIndex,nowIndex,res);
            this.trigger('itemsClick',[e,nextIndex,nowIndex,res]);
        },this));
    }

    var beforeLeave = null;

    var itemsClick = function(e,nextIndex,nowIndex,res){
        var target = e.target||e.currentTarget,
            items = this.options.items,
            next = nextIndex||$(target).closest('li').index(),
            index = this.$el.find('.sn-step .step-now').closest('li').index();
        var now = (nowIndex==0?0:nowIndex||index);
        beforeLeave = function(key){ //this.options.beforeLeave的响应
            if(items[key].beforeLeave){
                return items[key].beforeLeave();
            }else{
                console.log('还没有配置beforeLeave');
            }
        }
        if(items[next].click){
            var $formNow = this.$el.find('.sn-step>.formContainer form:eq('+now+')');
            var $formNext = this.$el.find('.sn-step>.formContainer form:eq('+next+')');
            var result;
            if(next!=index){//页面可以切换
                result = res||beforeLeave(now);
                if(result||result===undefined){//beforeLeave !=false
                    if($(target).parent().attr('class') == 'step-done'||'step-current'){//切换当前页面标注
                        this.$el.find('.sn-step .step-now').removeClass('step-now');
                        this.$el.find('.sn-step>.sn-stepbar>li:eq('+next+')>div>.step-name').addClass('step-now');
                    }
                                  
                    if($formNext.css('display')=='none'){//要进入的表单已经new 过了，只需显示/隐藏
                        fadeOut($formNow, function() {
                            $formNext.show();
                        });
                    }else{ //没有new过，需隐藏当前表单，new下一个表单                
                        fadeOut($formNow,function(){
                            items[next].click(e);
                        });                 
                    }
                }
            }else{
                if($formNext.css('display')=='block'){//i==index  点击当前进度
                    console.log('还在这一页')
                }else{//刚打开界面
                    items[next].click(e);
                } 
            }
        }
    };
    //淡隐动画
    function fadeOut(obj,callBack){
        obj.fadeOut('fast', callBack);
    };
    $.extend(objClass.prototype,{
        next:function(){
            var $now = this.$el.find('.sn-step .step-now').closest('li');
            var nowIndex = $now.index(),
                nextIndex = nowIndex+1, 
                $current = this.$el.find('.sn-step li:eq('+nextIndex+') .step-current'),
                $done = this.$el.find('.sn-step li:eq('+nextIndex+')>.step-done');
            if($now.attr('class') != 'step-last'){  
                var result = beforeLeave(nowIndex);
                if(result||result===undefined) {
                    result = 1;
                }else{
                    result = 0;
                }                  
                if($done.length||$current.length){ //将要进去的表单已经new过了，进度条已经改变过了，不需要再改变进度条的样式
                    this.$el.find('.sn-step li:eq('+nextIndex+') .step-num').trigger('click',[nextIndex,nowIndex,result]);
                }else{
                    if(result==1){//beforeLeave !=false 可以切换表单 ，改变进度条样式
                        this.$el.find('.sn-step .step-current').removeClass('step-current').addClass('step-done');
                        this.$el.find('.sn-step li:eq('+nextIndex+')').children().addClass('step-current');
                        this.$el.find('.sn-step .step-current .step-num').trigger('click',[nextIndex,nowIndex,result]);
                    }else{  //beforeLeave ==false,不能切换表单，不能改变样式，也不能触发click
                        console.log('不能改变进度')
                    }  
                }
            }else{
                console.log('已经是最后一步了');
            }
        },
        previous:function(){
            var $now = this.$el.find('.sn-step .step-now').closest('li');
            var nowIndex = $now.index();
            var nextIndex = nowIndex-1; 
            if($now.attr('class') != 'step-first'){
//          	$('.sn-step .step-current',this.$el).removeClass('step-current');
//              $('.sn-step li:eq('+nextIndex+')',this.$el).children().addClass('step-current').removeClass('step-done');
                this.$el.find('.sn-step li:eq('+nextIndex+') .step-num').trigger('click',[nextIndex,nowIndex]);
                this.$el.find('.sn-step li:eq('+nowIndex+') div').eq(0).removeClass('step-current')
                this.$el.find('.sn-step li:eq('+nextIndex+') div').eq(0).attr('class','step-current')
            }else{
                console.log('已经是第一步了');
            }
        },
        switchTo:function(stepClassName){
            var nextIndex = stepClassName.replace(/[^0-9]/ig,"")-1;
            var nowIndex = this.$el.find('.sn-step .step-now').closest('li').index();
            var $done = this.$el.find('.sn-step li:eq('+nextIndex+') .step-done');
            var $current = this.$el.find('.sn-step li:eq('+nextIndex+') .step-current');
            if($done.length||$current.length){
                this.$el.find('.sn-step li:eq('+nextIndex+') .step-num').trigger('click',[nextIndex,nowIndex]);
                this.$el.find('.sn-step li:eq('+nowIndex+') div').eq(0).removeClass('step-current')
                this.$el.find('.sn-step li:eq('+nextIndex+') div').eq(0).attr('class','step-current')
            }else{
                console.log('现在还不能跳转');
            }
        },
        get:function(stepClassName){
            var i = stepClassName.replace(/[^0-9]/ig,"")-1;
            var item = this.options.items[i];
            var data = {
                title : item.title,
                className:item.className,
                module:item.click
            }
            return data;
        }
    });
    // 判断是否为原生DOM
    var isDOM = function(obj){
        return obj.tagName ?true:false
    } 
    //解决ie下console.log()报错问题
    window.console = window.console || (function(){
        var c = {};
        c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function(){};
        return c;
    })();
    
    return objClass;
});

(function(c){var d=document,a='appendChild',i='styleSheet',s=d.createElement('style');s.type='text/css';d.getElementsByTagName('head')[0][a](s);s[i]?s[i].cssText=c:s[a](d.createTextNode(c));})
('@charset \"UTF-8\";\r\n\r\n/* 步骤条 */\r\n.sn-step { margin:0px auto;}\r\n.sn-step .sn-stepbar { margin:12px auto 0px;overflow:hidden;}\r\n.sn-step .sn-stepbar li { width:160px; float:left; text-align:center; list-style: none;}\r\n.sn-step .sn-stepbar .step-name { padding:3px 0px; color:#999; font-size: 12px; font-weight:700px; margin-top:5px;}\r\n.sn-step .sn-stepbar .step-time { margin-top:10px; color:#999; padding:8px 0px;}\r\n.sn-step .sn-stepbar .step-done .step-num { background-position:50% -100px; color: #FFF; }\r\n.sn-step .sn-stepbar .step-num { background:url(\'\') no-repeat 50% -60px; height:18px; line-height:18px; color:#999; font-size:12px;}\r\n.sn-step .sn-stepbar .step-first .step-current .step-num { background-position:50% -20px;}\r\n.sn-step .sn-stepbar .step-first .step-done .step-num { background-position:50% -120px; }\r\n.sn-step .sn-stepbar .step-current .step-num { background-position:50% 0px; color: #FFF; }\r\n.sn-step .sn-stepbar .step-last .step-num { background-position:50% -80px; }\r\n.sn-step .sn-stepbar .step-last .step-current .step-num { background-position:50% -40px; }\r\n.sn-step .sn-stepbar:after,.sn-step .sn-stepbar:before { display: block; content: \"\"; clear: both; height: 0; font-size: 0; overflow: hidden; }\r\n\r\n/* 依据UI规范 隐藏步数、重置当前步骤文字颜色 */\r\n.sn-step .sn-stepbar .step-done .step-name,.sn-step .sn-stepbar .step-current .step-name { color: #222; }\r\n.sn-step .sn-stepbar .step-num { text-indent: -10000px; }');
